import React, { useEffect } from 'react';
import { history } from 'umi';
import { connect } from 'dva';
import Header from './header';
import Footer from './footer';
import VideoLayout from './video';


const  LayoutPage = (props) => {
  const pathname = history.location.pathname;
  const { dispatch } = props;
  useEffect(()=>{
    const token = localStorage.getItem('token_umi_app')
    // if(!token) { history.push('/login') }
  },[])

  const LoginOut = () => {
    dispatch({ type: 'common/loginout' })
  }

  const renderDifferLayout = () => {
    switch (pathname) {
      case '/video':
        return <VideoLayout children={props.children}></VideoLayout>;
        break;
      default:
        return (
          <>
            <Header userInfo={props.userInfo} LoginOut={LoginOut} />
            {props.children}
            <Footer />
          </>
        );
        break;
    }
  };
  return <div>{renderDifferLayout()}</div>;
};

export default connect(({common})=>({
  userInfo: common.userInfo,
}))(LayoutPage)
